package com.geezdata.cps.cqrs.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.geezdata.cps.base.enums.ErrorCode;
import com.geezdata.cps.base.exceptions.MyException;


public class DelayEvent<T> extends AbstractEvent<T> {
	private static final Logger logger = LoggerFactory.getLogger(DelayEvent.class);
    private Long delayTimestamp;

    public DelayEvent(String name, T payload, Long delayTimestamp) {
        super(name, payload);
        setDelayTimestamp(delayTimestamp);
        checkDelayTimestamp();
    }

    public DelayEvent(T payload, Long delayTimestamp) {
        super(payload);
        setDelayTimestamp(delayTimestamp);
        checkDelayTimestamp();
    }
    
    public Long getDelayTimestamp() {
        return delayTimestamp;
    }
    
    private void setDelayTimestamp(Long delayTimestamp) {
    	this.delayTimestamp = delayTimestamp;
    }
    
    private void checkDelayTimestamp() {
        if (this.delayTimestamp == null || this.delayTimestamp <= 0) {
        	logger.error("delay timestamp can not be null or less than 0.");
            throw new MyException(ErrorCode.INTERNAL_SERVER_ERROR);
        }
    }

}
